
package algorithm.leetcode.problem_206;

import java.util.Arrays;

public class answer_1 {

  public static class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }
    public static ListNode reverseList(ListNode head) {
        ListNode before = head;
        ListNode after  = null;
        while (before != null) {
            ListNode node = before.next;
            before.next = after;
            after = before;
            before = node;
        }
        return after;
    }
    public static void main(String[] args) {
        ListNode node = new ListNode();
        node.val = 1;
        ListNode forNode = node;
        for (int i = 2; i <= 5; i++) {
            forNode.next = new ListNode(i);
            forNode = forNode.next;
        }
        reverseList(node);
    }

}
